{% extends "base.html" %}

{% if app_info %}
{% block head_title %}{{ app_info.app_name }} for {{ app_info.institution.display_form }} eCataloger Management{% endblock %}
{% endif %}

{% block more-js %}
 <script type="text/javascript" src="/js/jquery/jquery.treeview.js"></script>
<!--<script type="text/javascript" src="/js/jquery/ui/ui.accordion.js"></script>-->
<script type="text/javascript" src="/js/endeavor.js"></script>
<script type="text/javascript" src="/js/entity.js"></script>
<script type="text/javascript" src="/js/reports.js"></script>
{% endblock %}

{% block more-css %}
<link rel="stylesheet" href="/stylesheets/jquery/jquery.treeview.css" />
<link type="text/css" rel="stylesheet" href="/stylesheets/default.css" />
<link rel="stylesheet" href="http://dev.jquery.com/view/trunk/plugins/treeview/demo/screen.css" type="text/css" />
<!--<link rel="stylesheet" href="http://dev.jquery.com/view/trunk/plugins/treeview/jquery.treeview.css" type="text/css" />//-->
<link type="text/css" href="/stylesheets/jquery/ui.all.css" rel="stylesheet" />
{% endblock %}

{% block contents %}
<h2>{% if app_info %}{{ app_info.institution.display_form }} {% else %} [INSTITUTION NOT SET-UP] {% endif %} eCataloger Management<h2>
<div><a href="{{ auth_url }}">{{ auth_text }}</a>
<!-- START DASHBOARD TABSET //-->
<div id="main-tabs">
<ul>
 {% if user.admin or user.editor %}
 <li><a href="#users-admin-tab">User Administration</a></li>
 {% endif %}
 {% if user.editor %}
 <li><a href="#quick-manage-tab">Quick Manage</a></li>
 <li><a href="#adv-cataloger-tab">Advanced Cataloger Tools</a></li>
 {% endif %}
 <li><a href="#set-up-tab">{% if user.admin %}Set-up &amp; {% endif %}Help</a></li>
 <li><a href="#reports-tab">Reports</a></li>
</ul>
{% if user.admin or user.editor %}
<!-- START USER ADMIN TAB //-->
<div id="users-admin-tab">
<!-- START USER ACCORDION //-->
<div id="id-users-accordion">
 <!-- START ADMINISTRATORS SECTION //-->
 {% if user.admin %}
 <h3><a href="#">Administrators</a></h3>
 <div id="admin-section">
 <p>Users with administrator rights in eCataloger are able to change everything, including the application name and
    general collection management activities.</p>
 <button id="id-add-admin-user-btn" onclick="AddUserRight('Administrators','id-admin-users');">Add</button>
 <button id="id-delete-admin-user-btn" onclick="RemoveUserRight('Administrators','id-admin-users');" disabled="TRUE">Remove</button><br/>
 <select id="id-admin-users" size="4" onclick="UserRightSelectHandler('id-add-admin-user-btn','id-delete-admin-user-btn');">
 {% for record in all_users.admin %}
 <option value="{{ record.key }}">{{ record.user.email }}</option>
 {% endfor %}
 </select>
 <!-- END ADMINISTRATORS SECTION //-->
 </div>
 {% endif %}
 <!-- START EDITORS SECTION //-->
 {% if user.admin or user.editor %}
 <h3><a href="#">Editors</a></h3>
 <div id="editors-section">
 <p>Users with Editor rights can add/edit/remove all datastore entities but are unable to edit the application and collection information.
 </p>
 <button id="id-add-editor-user-btn" onclick="AddUserRight('Editors','id-editors-users');">Add</button>
 <button id="id-delete-editor-user-btn" onclick="RemoveUserRight('Editors','id-editors-users');" disabled="TRUE">Remove</button><br/>
 <select id="id-editors-users" size="4" onClick="UserRightSelectHandler('id-add-editor-user-btn', 'id-delete-editor-user-btn')">
 {% for record in all_users.editors %}
 <option value="{{ record.key }}">{{ record.user.email }}</option>
 {% endfor %}
 </select>
 <!-- END EDITORS SECTION //-->
 </div>
 <!-- START CONTRIBUTORS SECTION //-->
 <h3><a href="#">Contributors</a></h3>
 <div id="contrib-section">
 <p>User with Contributor rights can add comments and tag entities but cannot do original cataloging or change the application's configuration.</p>
 <button id="id-add-contrib-user-btn" onclick="AddUserRight('Contributors','id-contrib-users');">Add</button>
 <button id="id-delete-contrib-user-btn" onclick="RemoveUserRight('Contributors','id-contrib-users');" disabled="TRUE">Remove</button><br/>
 <select id="id-contrib-users" size="4" onClick="UserRightSelectHandler('id-add-contrib-user-btn', 'id-delete-contrib-user-btn')">
 {% for record in all_users.contributors %}
 <option value="{{ record.key }}">{{ record.user.email }}</option>
 {% endfor %}
 </select>
 <!-- END CONTRIBUTORS SECTION //-->
 </div>
<!-- END USER ACCORDION //-->
</div>
{% endif %}
<!-- END USER ADMIN TAB //-->
</div>
{% endif %}
<!-- START QUICK MANAGE TAB //-->
{% if user.editor %}
<div id="quick-manage-tab">
<h2>Quick Management for eCataloger <span id="id-quick-manage-mode"></span></h2>
<!-- START QUICK MANAGE FORM //-->
<input type="hidden" id="id-work-key" value="" />
<label for="endeavor-type-select">Select Type of Resource:</select>
<select id="id-endeavor-type-select" name="endeavor_type_select">
{% for endeavor_type in endeavor_types %}
<option value="{{ endeavor_type.class }}">{{ endeavor_type.pretty_name }}</option>
{% endfor %}
</select>
<input type="button" name="add_endeavor_button" value="Add" onclick="AddEndeavor('id-endeavor-type-select')" />
<input type="button" name="display_button" value="Display" onclick="DisplayEndeavors()" />
<input type="button" onclick="SaveEndeavor()" value="Save" id="id-save-endeavor-btn" disabled="disabled" />
<input type="button" value="Reset" onclick="ResetEndeavorForm()"/>
<div id="id-existing-endeavors-div">
<select id="id-existing-endeavors-select" name="existing-endeavors-select">

</select>
<button onclick="EditEndeavor()">Edit</button>
<button onclick="RemoveEndeavor()">Remove</button>
</div>
<!-- START TITLE FIELDSET //-->
<fieldset>
<legend>Title of Resource</legend>
<label>Title:</label><input type="text" name="title" id="id-title" size="60" /><br />
<label>Subtitle:</label><input type="text" name="subtitle" id="id-subtitle" /><br />
<label>Display label:</label><input type="text" name="display_label" id="id-title-display_label" size="60"/>
<input type="hidden" id="id-title-key" value="" />
<!-- END TITLE FIELDSET //-->
</fieldset>
<!-- START SUBJECTS, URLS, and PUBLISHER FIELDSET //-->
<fieldset>
<legend>Subjects, URLs, and Publisher</legend>
<table>
<tr>
<td valign="top">
<label>All Subjects</label><br/>
<select id="id-all-subjects" multiple="True" size="4">
{% for concept in concepts %}
<option value="{{ concept.key }}">{{ concept.display_form }}</option>
{% endfor %}
</select>
</td>
<td valign="center" align="center">
<button id="id-select-subj-bttn" onclick="MoveOption('id-all-subjects','id-concepts-select')" href="#">Select</button><br/>
<button id="id-remove-sub-bttn" onclick="RemoveOption('id-concepts-select')" href="#">Remove</button><br />
<button id="id-add-sub-bttn" onclick="AddOption('id-concepts-select','Concept')" href="#">Add</button>
</td>
<td valign="top">
<label>Subjects</label><br/>
<select id="id-concepts-select" name="concepts" multiple="True" size="4">

</select>
</td>
</tr>
</table>
<label>Primary access URL:</label><br/><input type="text" id="id-access-address" name="access_address" size="80" />
<input type="hidden" id="id-access-url-key" value="" />
<br/>
<label>Proxy access URL:</label><br/><input type="text" id="id-proxy-address" name="proxy_address" size="80" />
<input type="hidden" id="id-proxy-url-key" value="" />
<br/>
<table>
<tr>
<td valign="top">
<label>All Publishers:</label><br/>
<select id="id-all-corp-bodies" rows="4">
{% for org in corporate_bodies %}
<option value="{{ org.key }}">{{ org.display_form }}</option>
{% endfor %}
</select>
</td>
<td valign="center" align="center">
<button onclick="MoveOption('id-all-corp-bodies','id-publisher-select')">Select</button><br/ >
<button onclick="RemoveOption('id-publisher-select')">Remove</button><br />
<button onclick="AddOption('id-publisher-select','CorporateBody')">Add</button>
</td>
<td valign="top">
<label>Publisher</label><br/>
<select id="id-publisher-select" name="publisher">

</select>
</td>
</tr>
</table>
<!-- END SUBJECTS, URLS, and PUBLISHER FIELDSET //-->
</fieldset>
<!-- START ADDITIONAL INFO FIELDSET //-->
<fieldset>
<legend>Additional Information</legend>
<table>
<tr>
<td valign="top">
<label>Description:</label><br/>
<textarea name="description" id="id-endeavor-desc" cols="40" rows="3"></textarea>
<input type="hidden" id="id-desc-key" value="" />
</td>
<td valign="top">
<label>Language of Endeavor Meta-data:</label>
<select id="id-language-select">
{% for language in languages %}
<option value="{{ language.value }}">{{ language.display_form }}</option>
{% endfor %}
</select><br/>
<label>Is subscription?</label><input type="radio" name="is_subscription" id="is_subscription_yes" value="1">Yes</input>
<input type="radio" id="is_subscription_no" name="is_subscription" value="0">No</input><br/>
<label>Is trial?</label><input type="radio" name="is_trial" id="is_trial_yes" value="1">Yes</input>
<input type="radio" id="is_trial_no" name="is_trial" value="0">No</input><br/>
<label>Popularity Rating (0-100):</label><input type="text" id="id-popularity" name="popularity" size="6" />
</td>
</tr>
</table>
<!-- END ADDITIONAL INFO FIELDSET //-->
</fieldset>
<!-- END QUICK MANAGE TAB //-->
</div>
<!-- START ADVANCED CATALOGER TOOLS TAB //-->
<div id="adv-cataloger-tab">
<h2>Advanced Cataloger Tools</h2>
{{ entities }}
<table>
<tr>
<td>
<ul id="all-entities-tree" class="filetree">
{% for letter in all_entities %}
<li><span class="folder">{{ letter.0|upper }} ({{ letter.1|length }})</span>
<ul>
{% for class in letter.1 %}
<li><span class="folder">{{ class.name }} <button onclick="AddEntity('{{ class.value }}');javascript:scroll(0,0)">Add</button></span>
<ul>
{% for entity in class.existing %}
<li><span class="file"><a href="#" onclick="DisplayEntity('{{ entity.key }}')">{{ entity|pretty_entity }}</a>
 <button onclick="EditEntity('{{ entity.key }}')">Edit</button>
 <button onclick="DeleteEntity('{{ entity.key }}')">Delete</button></span></li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</td>
<td valign="top">
<div id="cataloger-action-display"></div>
</td>
</tr>
</table>
<!-- END ADVANCED CATALOGER TOOLS TAB //-->
</div>
{% endif %}
<!-- START SET-UP AND HELP TAB //-->
<div id="set-up-tab">
{% if user.admin %}
<fieldset>
 <legend>eCataloger Collection Administration</legend>
 <input type="button" value="Edit" onclick="EditAdmin()" id="id-edit-admin-btn" /><input type="button" value="Save" onclick="SaveAdmin()" id="id-save-admin-btn" disabled="TRUE" />
 <br/>
 <label>Application name:</label><input disabled="TRUE" type="text" value="{{ app_info.app_name }}" id="id-app_name" name="app_name" size="60" /><br/>
 <label>Institution:</label><br/>
 <table>
 <tr>
 <td valign="top">All institutions:</td>
 <td></td>
 <td valign="top">Your institution:</td>
 </tr>
 <tr>
 <td valign="top">
 <select id="id-set-up-corp-bodies" rows="4" disabled="TRUE">
{% for org in corporate_bodies %}
<option value="{{ org.key }}">{{ org.display_form }}</option>
{% endfor %}
</select>
</td>
<td valign="center">
<button disabled="TRUE" id="id-mve-admin-btn" onclick="MoveOption('id-set-up-corp-bodies','id-institution-select')">Select</button><br/ >
<button disabled="TRUE" id="id-rmv-admin-btn" onclick="RemoveOption('id-institution-select')">Remove</button><br />
<button disabled="TRUE" id="id-add-admin-btn" onclick="AddOption('id-institution-select','CorporateBody')">Add</button>
</td>
<td valign="top">
<select id="id-institution-select" name="institution" disabled="TRUE">
{% if app_info.institution %}
<option value="{{ app_info.institution.key }}">{{ app_info.institution.display_form }}</option>
{% endif %}
</select>
</td>
</tr>
<tr>
<td>
 <label>Start IP address:</label>
 <input type="text" name="start_ip" id="id-start_ip" size="50" value="{{ app_info.start_ip_addr }}" disabled="TRUE"/>
</td>
<td></td>
<td>
 <label>End IP address:</label>
 <input type="text" name="end_ip" id="id-end_ip" size="50" value="{{ app_info.end_ip_addr }}" disabled="TRUE"/>
</td>
</tr>
</table>
<input type="button" value="Local Datastore backup/restore" onclick="alert('NEEDS IMPLEMENTING')" />
<input type="button" value="Import Models from other eCataloger Collections" onclick="alert('NEEDS IMPLEMENTING')" />
<input type="button" value="Clear application cache" onclick="ClearCache()" />
</fieldset>
{% endif %}
<fieldset>
 <legend>Help Topics</legend>
 <label>Type of:</label>
 <select name="help_type_of" id="id-help_type_of" onclick="PopulateHelpTopics()" onblur="">
 <option>Please select...</option>
 <option value="howdoi">How do I</option>
 <option value="general">General</option>
 <option value="all">All</option>
 </select>
 <select id="id-help-topics-select">

 </select>
 <button value="Edit" disabled="TRUE" id="id-edit-help-topic-btn" onclick="EditHelpTopic()">Edit</button>
 <button value="Add" id="id-add-help-topic-btn" onclick="AddHelp()">Add</button>
 <button value="Save" disabled="TRUE" id="id-save-help-topic-btn" onclick="SaveHelp()">Save</button>
 <button value="Remove" disabled="TRUE" id="id-delete-help-topic-btn" onclick="alert('DELETE HELP TOPIC')">Remove</button>
 <br />
 <input type="hidden" name="help-key" id="id-help-key" />
 <label>Question:</label><input type="text" id="id-help_question" name="help_question" size="60" disabled="TRUE" />?<br/>
 <label for="id-help_answer">Answer:</label><br/>
 <textarea rows="4" cols="60" name="help_answer" id="id-help_answer" disabled="TRUE"></textarea><br/>
<!-- END SET-UP AND HELP TAB //-->
</div>
<!-- START REPORTS TAB //-->
<div id="reports-tab">
<h2>Reports</h2>
<!-- START REPORTS TABSET //-->
<div id="reports-tabset">
<ul>
{% if user.admin %}
  <li><a href="#admin-reports-tab">Administrative</a></li>
{% endif %}
  <li><a href="#budget-reports-tab">Budget</a></li>
  <li><a href="#usage-reports-tab">Usage</a></li>
</ul>
{% if user.admin %}
<!-- START ADMIN REPORTS TAB //-->
<div id="admin-reports-tab">

<!-- END ADMIN REPORTS TAB //-->
</div>
{% endif %}
<!-- START BUDGET REPORTS TAB //-->
<div id="budget-reports-tab">

<!-- END BUDGET REPORTS TAB //-->
</div>
<!-- START USAGE REPORTS TAB //-->
<div id="usage-reports-tab">
<select id="usage-type-select">
{% for endeavor_type in endeavor_types %}
<option value="{{ endeavor_type.class }}">{{ endeavor_type.pretty_name }}</option>
{% endfor %}
<option value="HelpTopics">Help Topics</option>
<option value="all">All</option>
</select>
<input type="button" onclick="DisplayReport('use','usage-type-select');" value="Generate" />
<div id="usage-report-display">

</div>
<!-- END USAGE REPORTS TAB //-->
</div>
<!-- END REPORTS TABSET //-->
</div>
<!-- END REPORTS TAB //-->
</div>
<!-- END DASHBOARD TABSET //-->
</div>
{% endblock %}

{% block page-dialogs %}
<div id="get-entity-dialog" title="Get Entity">
<input type="hidden" name="calling_element" id="id_calling_element" value="" />
<select id="id_entity_select" name="entity_select">
{% for letter in all_entities %}
<optgroup label="{{ letter.0 }}">
{% for class in letter.1 %}
 <option value="{{ class.value }}">{{ class.name }}</option>
{% endfor %}
</optgroup>
{% endfor %}
</select>
<button onclick="PopulateDisplay('id_entity_select')">Display</button>
<div id="id-dialog-entity-results"></div>
</div>
<!-- BEGIN INITIAL SETUP DIALOG //-->
{% if not app_info %}
<div id="initial-setup-dialog" title="Initial E-Library Setup">
<h3>E-Library Initial Configuration.</h3>
<label>Your e-mail:</label><input type="id-initial-admin" value="{{ user.email }}" /><br/>
<fieldset>
<legend>Your eCataloger user rights:</legend>
<input type="checkbox" id="id-admin-chkbx" name="admin-chkbx" value="yes" checked="checked">Administrator</input>
<input type="checkbox" id="id-editor-chkbx" name="editor-chkbx" value="yes">Editor</input>
<input type="checkbox" id="id-contributor-chkbx" name="contributor-chkbx" value="yes">Contributor</input>
</fieldset>
<label>eCataloger Application name:</label><br/>
<input id="id-init-app-name" size="60" /><br/>
<label>Your institution's name:</label><br/><input id="id-init-corp-name" size="60" /><br />
<label>Your institutions's address:</label><br/><textarea id="id-init-corp-addr" cols="40" rows="4"></textarea>
<br/>
<div style="alignment:center">
<input  type="button" value="Save" onclick="InitConfig()" />
</div>
<!-- END INITIAL SETUP DIALOG //-->
</div>
{% endif %}
{% endblock %}

{% block body-js %}

<script>
 $(document).ready(function() {
   $("#main-tabs").tabs();
   $("#all-entities-tree").treeview({
     collapsed: true});
   $("#id-users-accordion").accordion({ autoHeight: false });
   $("#reports-tabset").tabs();
   $("#get-entity-dialog").dialog({
      autoOpen: false,
      modal: true,
	  minHeight: 300,
	  minWidth: 500,
      buttons: {
       "Ok": function() {
	     UpdateCallingElement();
         $(this).dialog("close");
       },
	   "Cancel": function() {
	     $(this).dialog("close");
	   }
      }
      });
{% if not app_info %}
	$("#initial-setup-dialog").dialog();
{% endif %}
 });

 //$(window).load(function() {
            //setTimeout(function() { $("#loading").fadeOut('slow'); $("#wrapper").fadeIn('slow'); }, 2000);
        //});
</script>
{% endblock %}

